<?php
if ($invoice) {
    $shiping = 0;
    $discount = 0;
    $total = 0;
    ?>
<h1><span></span><?= lang($invoice->title) . ' - ' . lang('label_inv_num') . ': ' ?><span style="font-family: sans-serif"><?= strtoupper($invoice->inv_num) ?></span></h1>

    <ul class="breadcrumb">
        <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
        <li><a href="<?= base_url('user/profile') ?>"><?= lang('label_profile') ?></a></li>
        <li><a href="<?= base_url('invoicies') ?>"><?= lang('label_your_invoicies') ?></a></li>
        <li><?= lang('label_inv_num') . ': ' . strtoupper($invoice->inv_num) ?></li>
    </ul>


    <div class="page">
        <?php $this->load->view('template/default/invoicies/top') ?>

        <div style="overflow:hidden;">
            <div class="invoice">
                <b>&raquo; <?= lang('label_created_date') ?> :</b>  <?= $invoice->create_date ?>
                <br /><b>&raquo; <?= lang('label_confirm_date') ?> :</b>  <?php
                $pa = $invoice->confirm_status;
                if ($pa == 'YES') {
                    echo '<i>' . lang('label_confirm_yes') . '</i> ' . $invoice->confirm_date;
                } else {
                    echo '<i>' . lang('label_confirm_no') . '</i> ';
                }
                ?>
                <br /><b>&raquo; <?= lang('label_payment_date') ?> :</b>  <?php
                $pa = $invoice->payment_status;
                if ($pa == 'YES') {
                    echo '<i>' . lang('label_payment_yes') . '</i> ' . $invoice->payment_date;
                } else {
                    echo '<i>' . lang('label_payment_no') . '</i> ';
                }
                ?>
            </div>
            <table id="tablestyle3">
                <thead>
                    <tr>
                        <th style="width:38%;"><?= lang('label_items') ?></th>
                        <th style="width:11%;"><?= lang('label_product_price') ?></th>
                        <th style="width:10%;"><?= lang('label_product_quentity') ?></th>
                        <th style="width:11%;"><?= lang('label_shiping') ?></th>
                        <th style="width:10%;"><?= lang('label_discount') ?></th>
                        <th style="width:20;"><?= lang('label_total') ?></th>
                    </tr>
                </thead>

                <tbody>
                    <?php if (isset($items)) { ?>
                        <?php foreach ($items as $item) { ?>
                            <tr <?php
                            foreach ($sdata as $dt) {
                                if ($dt->item_id == $item->id && $dt->canceled == 'YES') {
                                    ?>
                                        style="background-color: #f7e4e4; text-decoration: line-through" title="<?= lang('label_wallet_rejected') ?>"
                                    <?php } elseif ($dt->item_id == $item->id && $dt->accept == 'YES') { ?>
                                        style="background-color: #e8f2e6" title="<?= lang('label_accept') ?>"
                <?php }
            } ?>>
                                <td><?= $item->title ?></td>
                                <td><?= $item->price ?></td>
                                <td><?= $item->amount ?></td>
                                <td><?= $item->shiping ?></td>
                                <td><?= $item->discount ?></td>
                                <td><b><?= $item->total_price ?></b> <?= lang('label_rial') ?></td>
                            </tr>
        <?php } ?>
    <?php } else { ?>
                    <td><?= lang($invoice->title) ?></td>
                    <td><?= $invoice->total ?></td>
                    <td>--</td>
                    <td><?= $invoice->shiping ?></td>
                    <td><?= $invoice->discount ?></td>
                    <td><b><?= $invoice->must_pay ?></b> <?= lang('label_rial') ?></td>
    <?php } ?>

                <tr>
                    <td colspan="5"><?= lang('label_sub_total') ?></td>
                    <td><b><?= $invoice->total ?></b> <?= lang('label_rial') ?></td>
                </tr>
                <tr>
                    <td colspan="5"><?= lang('label_shiping_total') ?></td>
                    <td><b><?= $invoice->shiping ?></b> <?= lang('label_rial') ?></td>
                </tr>
                <tr>
                    <td colspan="5"><?= lang('label_discount_total') ?></td>
                    <td><b><?= $invoice->discount ?></b> <?= lang('label_rial') ?></td>
                </tr>
                <tr>
                    <td colspan="5"><strong><?= lang('label_item_total') ?></strong></td>
                    <td><span><?= $invoice->must_pay ?></span> <?= lang('label_rial') ?></td>
                </tr>
                </tbody>
            </table>

            <div class="submit">
                <?php if ($invoice->payment_status == 'NO' && $invoice->confirm_status == 'YES') { ?>
                    <a href="<?= base_url() ?><?= get_segment(1) ?>/pay/<?= $invoice->inv_num ?>"><?= lang('label_pay_the_bill') ?></a>
                <?php } ?>
                <?php if ($invoice->payment_status == 'NO') { ?>
                    <a href="<?= base_url() ?><?= get_segment(1) ?>/cancel/<?= $invoice->inv_num ?>"><?= lang('label_cancel') ?></a>
        <?php } ?>
            </div></div></div> 
        <?php
    } else {
        show_404();
    }
    ?>